#!/bin/bash

echo "===start to build==="
chmod +x /root/repo/scripts/common_scripts/common.sh
source /root/repo/scripts/common_scripts/common.sh

set -e
set -o pipefail

handle_error() {
  local exit_code=$?
  echo "Error occurred in script at line: ${1} with exit code: ${exit_code}"
  exit $exit_code
}

trap 'handle_error ${LINENO}' ERR

GIT_USER=$1
GIT_TOKEN=$2
CONAN_USER=$3
CONAN_PASSWORD=$4
REPO=$5

function main() {
  prepare_software
  prepare_bingo
  prepare_git $GIT_USER $GIT_TOKEN
  prepare_conan $CONAN_USER $CONAN_PASSWORD
  prepare_sdk
  repo_name=$(echo "$REPO" | rev | cut -d/ -f1 | rev | cut -d. -f1)
  build_component /root/repo/${repo_name}/
  upload_conan /root/repo/${repo_name}/
}

main

exit 0
